package extractor;

import java.sql.SQLException;

import db.QueryPool;

public class UnneccesaryCharacterHandler {
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		QueryPool query = new QueryPool();
		query.tweetRefinery();
		
	}
	
	public String remover(String text) {
		while (text.indexOf("http://") >= 0) {
			text = removeUnneccesaryCharacter(text, "http://");
		}
		
		while (text.indexOf("RT") >= 0) {
			text = removeUnneccesaryCharacter(text, "RT");
		}
		
		while (text.indexOf("@") >= 0) {
			text = removeUnneccesaryCharacter(text, "@");
		}
		
		while (text.indexOf("#") >= 0) {
			text = removeUnneccesaryCharacter(text, "#");
		}
		
		while (text.indexOf("&") >= 0) {
			text = removeUnneccesaryCharacter(text, "&");
		}
		
		while (text.indexOf("\\u") >= 0) {
			System.out.println("here");
			text = removeUnneccesaryCharacter(text, "\\u");
		}
		System.out.println("refineried text = " + text);
		return text;
	}

	private String removeUnneccesaryCharacter(String text, String character) {
		int start = 0;
		int end = 0;
		boolean check = false;
		String temp = text.substring(text.indexOf(character), text.length());
		if (temp.indexOf(' ') != -1) { 
			temp = temp.substring(temp.indexOf(' '), temp.length());
		} else {
			temp = "";
		}
		return text.substring(0,text.indexOf(character)) + temp;
	}
}
